<?php
/**
 * 商品规格
 * User: yuanxuncheng
 * Date: 2016-12-21
 * Time: 22:39
 */

namespace app\api\model\dao;

use think\Model;
use think\Db;

class GoodsSpec extends Model
{
    //set talbename
    protected $table = 'goods_spec';
    //set primary key
    protected $pk = 'goods_spec_id';

    /**
     * @desc 增加商品规格
     * @param $goods_id
     * @param $spec_name
     * @param $price
     * @return false|int
     */
    public function addGoodsSpec($param)
    {
        return $this->allowField(true)->save($param);
    }

    public function addGoodsSpecBatch($param)
    {
        return $this->allowField(true)->saveAll($param);
    }

    /**
     * @desc 获取商品规格
     * @param $goods_id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getGoodsSpecByGoodsid($goods_id)
    {
        $conds = array(
            'goods_id' => $goods_id,
        );
        $field = '*';
        return Db::table($this->table)->where($conds)->field($field)->select();
    }

    /**
     * @desc 获取商品规格
     * @param $goods_id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getGoodsSpecByid($goods_spec_id)
    {
        $conds = array(
            'goods_spec_id' => $goods_spec_id,
        );
        $field = '*';
        return Db::table($this->table)->where($conds)->field($field)->select();
    }
}
